using System.Data;
using System.Linq;
using ExampleWebApplication.Infraestruture.NHibernate;
using NHibernate;
using NHibernate.Linq;
using TelerikMvcGridCustomBindingHelper.NHibernate.ORMIntegration;
using TelerikMvcGridCustomBindingHelper.ORMIntegration;

namespace ExampleWebApplication.Infraestruture
{
    public class NHibernateIntegration : ORMIntegration, INHibernateIntegration
    {
        public IQueryOver<TEntity, TEntity> QueryOver<TEntity>() where TEntity : class
        {
            return NHibernateHelper.CurrentSession.QueryOver<TEntity>();
        }
    }

    public class ORMIntegration : IORMIntegration
    {
        public void BeginTransaction(IsolationLevel isolationLevel)
        {
            NHibernateHelper.CurrentSession.Transaction.Begin(isolationLevel);
        }

        public void CommitTransaction()
        {
            NHibernateHelper.CurrentSession.Transaction.Commit();
        }

        public void RollBackTransaction()
        {
            NHibernateHelper.CurrentSession.Transaction.Rollback();
        }

        public IQueryable<TEntity> Query<TEntity>()
        {
            return NHibernateHelper.CurrentSession.Query<TEntity>();
        }

        public void Dispose()
        {
            NHibernateHelper.CurrentSession.Close();
            NHibernateHelper.CurrentSession.Dispose();
        }
    }
}